package 数组;

import java.util.Arrays;

/**
 * @Author Weton Li
 * @Date 2021/4/28 12:08
 */
public class 丢失的数字 {

    public static int method(int[] arr){

        Arrays.sort(arr);

        int st = 0;
        int en = arr.length-1;
        int n = arr.length;
        if (arr[st] != 0) {
            return 0;
        }
        if (arr[en]!=n){
            return n;
        }
        int i = 1;
        while (i < n) {
            if (arr[i] - arr[i - 1] > 1) {
                return arr[i]-arr[i-1];
            }
            i++;
        }

        return 0;
    }

    public static void main(String[] args) {
        int[] input = {3,0,1};
        System.out.println(method(input));
    }
}
